package com.leostadyn.stackfarm.timestatistics.model.mentity;

import com.leostadyn.stackfarm.timestatistics.model.bean.LoginBean;
import com.leostadyn.stackfarm.timestatistics.model.minterface.ILoginModel;
import com.leostadyn.stackfarm.timestatistics.net.api.AdminApi;
import com.leostadyn.stackfarm.timestatistics.net.base.OriginalSubscriber;
import com.leostadyn.stackfarm.timestatistics.net.base.ResponseThrowable;

import io.reactivex.disposables.CompositeDisposable;


public class LoginModel {
    public static void judge(final String account, final String password, CompositeDisposable compositeDisposable, final ILoginModel callback) {

        AdminApi.getInstance().login(account, password).subscribe(new OriginalSubscriber<LoginBean>(compositeDisposable) {

            @Override
            public void onError(ResponseThrowable e) {
                callback.onFailure(e.getMsg());
                callback.onCompleted();

            }

            @Override
            public void onNext(LoginBean loginBean, String msg) {
                if (loginBean != null)
                    callback.onSuccess(loginBean);
                else
                    callback.onFailure(msg);
                callback.onCompleted();
            }
            @Override
            public void onComplete() {
                callback.onCompleted();
            }
        });
    }
}
